<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <style>
    .upload {
      width: 300px;
      height: 300px;
      border: 1px solid black;
      display: flex;
      flex-direction: column;
      justify-content: center;
      align-items: center;
    }

    .click-upload {
      cursor: pointer;
    }

    #file {
      display: none;
    }
  </style>
  <body>
    <div class="upload">
      <p class="click-upload">+点击上传</p>
      <p>请拖拽上传</p>
      <input type="file" id="file" />
    </div>

    <script>
      const upload = document.querySelector(".upload");
      const file = document.querySelector("#file");

      upload.addEventListener("click", () => {
        file.click();
      });

      file.addEventListener("change", (e) => {
        console.log(e.target.files[0]);
      });

      upload.addEventListener("dragover", (e) => {
        e.preventDefault();
      });

      upload.addEventListener("drop", (e) => {
        e.preventDefault();
        console.log(e.dataTransfer.files[0]);
      });
    </script>
  </body>
</html>
